using UnityEngine;
using UnityEditor;

public class HierarchyExtention
{
    [MenuItem("GameObject/Create Custom GameObject",false,0)]
    static void ExtendGameObjectEntry()
    {
        
    }

    [InitializeOnLoadMethod]
    static void Initialize()
    {
        EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI;
    }

    private static void OnHierarchyGUI(int instanceid, Rect selectionrect)
    {
        // Add delete btn
        if (Selection.activeObject != null && instanceid == Selection.activeObject.GetInstanceID())
        {
            var rect = new Rect(selectionrect.width - 10, selectionrect.y, 100, selectionrect.height);
            if (GUI.Button(rect, "Delete"))
            {
                Debug.Log("You try to delete this GameObject");
                GameObject.DestroyImmediate(Selection.activeObject);
            }
        }
        
        // rewrite ContextMenu
        var e = Event.current;
        if (e != null && e.button == 1 && e.type == EventType.MouseUp)
        {
            var rect = new Rect(e.mousePosition, new Vector2(100, 0));

            EditorUtility.DisplayPopupMenu(rect, "GameObject/3D Object", null);
            e.Use();
        }
        
        
    }
}